#include "game.h"
#include<bits/stdc++.h>
using namespace std;
vector<int> qq;
const int maxn = 1e5 + 5;
vector<int> adj[maxn];
bool vis[maxn];
bool vs[maxn];
vector<int> ans;
vector<int> cyc;
void dfs(int now){
    vs[now] = 1; cyc.push_back(now);
    for(auto t : adj[now]){
	if(vs[t]) continue;
	dfs(t);
    }
    return ;
}
std :: vector<int> guess(int n, int limit) {
    qq.resize(n);
    for(int i = 1; i <= n; i ++)
	qq[i - 1] = i;
    int qans = count(qq);
    for(int i = 1;i <= n;i++){
	if(vis[i]) continue;
	for(int j = i + 1;j <= n;j++){
	    swap(qq[i - 1], qq[j - 1]);
	    int nans = count(qq);
	    if(nans == qans + 2){
		adj[i].push_back(j); adj[j].push_back(i);
		vis[i] = vis[j] = 1;
	    } else if(nans == qans + 1){
		adj[i].push_back(j); adj[j].push_back(i);
		vis[i] = 1;
	    }
	    swap(qq[i - 1], qq[j - 1]);
	}
	if(vis[i] == 0){
	    adj[i].push_back(i);
	}
    }
    ans.resize(n); 
    for(int i = 1;i <= n;i++){
	if(vs[i]) continue;
	cyc.clear(); dfs(i);
	if(cyc.size() == 1){
	    ans[i - 1] = i; continue;
	}
	int L = cyc.size();
	for(int j = 1;j <= n;j++) qq[j - 1] = j;
	for(int i = 0;i < cyc.size();i++){
	    qq[cyc[i] - 1] = cyc[(i + 1) % L];
	}
	int nans = count(qq);
	if(nans > qans){
	    for(int i = 0;i < cyc.size();i++){
		ans[cyc[i] - 1] = cyc[(i + 1) % L];
	    }
	} else {
	    for(int i = 0;i < cyc.size();i++){
		ans[cyc[i] - 1] = cyc[(i + L - 1) % L];
	    }
	}
    }
    return ans;
}
